package paixu;

import java.util.Date;

public class ShellSort {
    public static void main(String[] args) {
        int arr [] = new int[8000000];
        for (int i = 0;i<8000000;i++){
            arr[i]= (int) (Math.random()*8000000);
        }
        Date date = new Date();
        System.out.println("排序前:"+date);
        shellSort(arr);
        Date date1 = new Date();
        System.out.println("排序后:"+date1);
//        System.out.println(Arrays.toString(arr));
    }
    public static void shellSort(int arr[]){
        for (int i = (arr.length/2) ; i>0 ; i/=2){
            for (int j = i;j<arr.length;j++){
                int temp = j;
                int tempValue=arr[j];
                if (arr[j]<arr[j-i]){
                    while (temp-i>=0 && arr[temp-i]>tempValue){
                        arr[temp]=arr[temp-i];
                        temp-=i;
                    }
                        arr[temp]=tempValue;
                }
            }
        }
    }
}
